#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n;
map<string, int> mp;

int main()
{
	freopen("network.in", "r", stdin);
	freopen("network.out", "w", stdout);

	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++)
	{
		string typ, add;
		cin >> typ >> add;
		
		bool flag = true;
		int cnt = 0;
		for (int j = 0; j < add.size() && flag; j++)
		{
			ll u = 0;
			
			int k = j;
			while (j < add.size() && add[j] != '.' && add[j] != ':' && flag)
			{
				u = u * 10 + ll(add[j] - '0');
				j++;
			}
			
			cnt++;
			
			if (j == k)
				flag = false;
				
			if (add[k] == '0' && j - k > 1)
				flag = false;
				
			if (j == add.size() && (cnt != 5 || u < 0LL || u > 65535LL))
				flag = false;
			else if (add[j] == '.' && (u < 0LL || u > 255LL || cnt > 3))
				flag = false;
			else if (add[j] == ':' && (cnt != 4 || u < 0LL || u > 255LL))
				flag = false;
		}
		
		if (!flag)
		{
			puts("ERR");
			continue;
		}
		
		if (typ == "Server")
		{
			if (mp.count(add))
				puts("FAIL");
			else
			{
				mp[add] = i;
				puts("OK");
			}	
		}
		else
		{
			if (!mp.count(add))
				puts("FAIL");
			else
				printf("%d\n", mp[add]);
		}
	}
	
	return 0;
}
